package com.guqj.rmi;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class RmiServer implements RmiHello {

	@Override
	public String sayHello() throws RemoteException {
		return "hello Rmi";
	}

	public static void main(String[] args) {
		try {
			int port = 1099;
			// 创建本机 1099 端口上的RMI registry
			Registry registry = LocateRegistry.createRegistry(port);
			RmiServer obj = new RmiServer();
			RmiHello stub = (RmiHello) UnicastRemoteObject.exportObject(obj, port);
			registry.bind("Hello", stub);
			System.out.println("Server Ready");	
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
